home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / adynware / q_count.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  1.6 KB  |  70 lines

  1. package q_count;
  2. use strict;
  3. use adynware::utility;
  4.  
  5. my %q__activeQueryCount = ();
  6. my $__imageQueryCount = 0;
  7.  
  8. sub GetPossibleNonImageQueryCount
  9. {
  10.         return scalar(keys %q__activeQueryCount) - $__imageQueryCount;
  11. }
  12.  
  13. sub IncrementQueryCount
  14. {
  15.         my($target) = @_;
  16.         #utility::Log("increment query count:fetching $target");
  17.         $__imageQueryCount++ if utility::IsImage($target);
  18.         $q__activeQueryCount{$target} = 1;
  19. }
  20.  
  21. sub DecrementQueryCount
  22. {
  23.         my($target) = @_;
  24.         #utility::Log("decrement query count:$target done");
  25.         $__imageQueryCount-- if utility::IsImage($target);
  26.         delete($q__activeQueryCount{$target});
  27. }
  28.  
  29. sub GetQueryCount
  30. {
  31.         return scalar(keys %q__activeQueryCount);
  32. }
  33.  
  34. sub GetQueryCountString
  35. {
  36.         my @k = keys %q__activeQueryCount;
  37.         my $s = scalar(@k);
  38.         $s .= " active queries";
  39.         if (scalar(@k))
  40.         {
  41.                 $s .= ": [ ";
  42.                 foreach (@k)
  43.                 {
  44.                         $s .= $_ . " ";
  45.                 }
  46.  
  47.                 $s .= "]";
  48.         }
  49.         return $s;
  50. }
  51.  
  52.  
  53. sub GuardAgainstCorruptQueryCount
  54. {
  55.         my($idleCount) = @_;
  56.         return $idleCount + 1 unless $idleCount > 3;
  57.         # we have been idle for a long time.  Just in case the query count
  58.         # is screwed up, arbitrarily remove a query from the count:
  59.         my @activeQueries = keys %q__activeQueryCount;
  60.         if (@activeQueries)
  61.         {         
  62.                 utility::Log("guarding against query count corruption");
  63.                 delete($q__activeQueryCount{$activeQueries[0]}) ;
  64.         } 
  65.         return 0;
  66. }
  67.  
  68.  
  69. 1;
  70.